
function UniverseUser() {
    this.users = {                  // 所有报名的玩家数据
        /*uid : {
            _id:uid,
            info:{},
            status:{},
            role:{},
            team:{},
            equip:{},
            tech:{},
            league:{},
        }*/
    };
}

UnieverseUser.create = function() {

    var serverWar = {
        _id: 'server_war', 
        top32_player:initTop32Players,
        server_war: initServerWar, 
        top_replay:{},
        replay_count:0,
    };

    gDBWorld.insert(serverWar, function(err, result){});
};

UniverseUser.prototype = {
    init : function(callback) {
        // 读取所有玩家数据
        var cursor = gDBUser.find();
        cursor.each(function(err, item){
            if( err ) {
                callback && callback(false);
            }
             
            if( item ) {
                this.users[item._id] = item;
            }

            if( cursor.isClosed() ) {
                callback && callback(true);
            }
        }.bind(this));
    },

    _init : function() {
    },

    addUpdate : function(key, value) {
        this.updates[key] = value;
    },

    save : function(callback) {
        if( Object.keys(this.updates).length == 0 ) {
            callback && callback(true);
            return;
        }
        
        var updates = this.updates;
        gDBWorld.update({_id : 'league_war'}, {$set:updates}, function(err, result){
            if( err ) {
                ERROR(err);
                ERROR(updates);
                callback && callback(false);
            }else {
                callback && callback(true);
            }
        });

        this.updates = {};
    },
}
